package tsing.javase.thread.queue;

import org.springframework.util.StringUtils;

import java.io.*;
import java.util.concurrent.ArrayBlockingQueue;

/**
 * @Author Tsing/吴清平
 * @Date 2022/10/20 17:08
 * @Version 1.0
 */
public class QueueDemo {

    private static  ArrayBlockingQueue<String> queue = new ArrayBlockingQueue<>(1000000);




    public static void main(String[] args) throws IOException {
        new QueueDemo().readData();

        while(queue.size()>0){
            System.out.println("data is :"+queue.poll());
        }

    }
    public void readData() throws IOException {
        String path = "G:\\湖南科创信息技术有限公司\\2022\\电子渠道事业部\\批退工具-李想\\举例文件\\33.6.txt";
        File file = new File(path);
        BufferedReader buffer = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"), 8 * 1024 * 1024);  //使用缓冲流读
        int i = 0;
        while (buffer.ready()) {
            //数据处理
            try {
                String s = buffer.readLine();
                s = s.replaceAll("\t", ",");
                s = s.replaceAll(" ", "").replaceAll("，", ",");
                if (s.toUpperCase().contains("[a-zA-Z]") || s.toUpperCase().contains("USERID")) {
                    System.out.println("第一行标题，不做处理");
                    continue;
                }
                if (StringUtils.hasLength(s) && s.length() >= 11) {
                    s = getStr(s);
                    String[] split = s.split(",");
                    if (split[0].length() < 11) {
                        System.out.println((s + "长度小于11，错误"));
                        continue;
                    }
                    queue.add(s);
                    i++;
                } else {
                    continue;
                }
            } catch (IOException e) {

            }

        }

    }


    public static String getStr(String string){
//        String string = ",|123abcABC!@#$%^&*()-_+={}[];:',<.>/?";
//        string = string.replaceAll("[^0-9a-zA-Z]",""); // 只保留数字和英文字母
        string = string.replaceAll("[^0-9,]",""); //只保留数字和英文逗号


        return string;
    }

}
